package com.fufan.mtsaas.modules.base.processinfo.service.impl;


import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.ResStatus;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.base.processinfo.bo.request.ProcessInfoQueryRequest;
import com.fufan.mtsaas.modules.base.processinfo.bo.request.ProcessInfoSaveRequest;
import com.fufan.mtsaas.modules.base.processinfo.model.PProcessInfo;
import com.fufan.mtsaas.modules.base.processinfo.dao.PProcessInfoDao;
import com.fufan.mtsaas.modules.base.processinfo.response.PProcessInfoResponse;
import com.fufan.mtsaas.modules.base.processinfo.service.PProcessInfoSvc;

import com.fufan.mtsaas.util.ParamUtil;
import com.github.pagehelper.ISelect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <p>
 * 流程处理表 服务实现类
 * </p>
 *
 * @author Liby
 * @since 2024-12-16
 */
@Service("PProcessInfoSvcImpl")
@Slf4j
@Primary
public class PProcessInfoSvcImpl extends ServiceImpl<PProcessInfoDao, PProcessInfo> implements PProcessInfoSvc {
    @Autowired
    private PProcessInfoDao entitymDao;

    /**
     * 查询
     *
     * @param map
     * @return Result.class
     */
    @Override
    public Result doQueryPage(ProcessInfoQueryRequest map) {

        Result<PProcessInfoResponse> result = new Result<>();
        Page<PProcessInfoResponse> page = new Page<>();
        long total = com.github.pagehelper.PageHelper.count(new ISelect() {
            @Override
            public void doSelect() {
                entitymDao.queryAllByLimit(page, map);
            }
        });

        // 分页
        ParamUtil.setPage(map.getPageSize(), map.getCurrentPage(), page);
        //分页查询
        List<PProcessInfoResponse> list = entitymDao.queryAllByLimit(page, map);

        page.setRecords(list);
        page.setTotal((int) total);
        result.setResStatus(ResStatus.STATUS_SUCCESS);
        result.setResMsg(ResStatus.STATUS_SUCCESS_MSG);
        result.setResData(page);

        return result;
    }

    @Override
    public Result doQueryAll(ProcessInfoQueryRequest map) {
        Result<PProcessInfoResponse> result = new Result<>();
        Page<PProcessInfoResponse> page = new Page<>();
        long total = com.github.pagehelper.PageHelper.count(new ISelect() {
            @Override
            public void doSelect() {
                entitymDao.queryAllByLimit(page, map);
            }
        });

        // 分页
        ParamUtil.setPage(map.getPageSize(), map.getCurrentPage(), page);
        //分页查询
        List<PProcessInfoResponse> list = entitymDao.queryAllByLimit(page, map);

        page.setRecords(list);
        page.setTotal((int) total);
        result.setResStatus(ResStatus.STATUS_SUCCESS);
        result.setResMsg(ResStatus.STATUS_SUCCESS_MSG);
        result.setResData(page);

        return result;
    }

    /**
     * 新增
     *
     * @param entitym
     * @param requestPojo
     * @return Result.class
     */
    @Override
    @Transactional
    public Result doSave(ProcessInfoSaveRequest entitym, RequestPojo requestPojo) {
        Result result = new Result();


        return result;

    }

    /**
     * 修改
     *
     * @param entitym
     * @param requestPojo
     * @return Result.class
     */
    @Override
    @Transactional
    public Result doUpdate(ProcessInfoSaveRequest entitym, RequestPojo requestPojo) {
        Result result = new Result();


        return result;

    }

    /**
     * 删除
     *
     * @param map
     * @return Result.class
     */
    @Override
    @Transactional
    public Result doDelete(ProcessInfoQueryRequest map, RequestPojo requestPojo) {
        Result result = new Result();

        return result;

    }
}
